package com.yaozheng.vocationaltraining.service.impl;

import com.yaozheng.vocationaltraining.iview.BaseView;
import com.yaozheng.vocationaltraining.iview.IBaseView;
import com.yaozheng.vocationaltraining.iview.IMastersTourView;
import com.yaozheng.vocationaltraining.service.MastersTourService;
import com.yaozheng.vocationaltraining.utils.Constants;
import com.yaozheng.vocationaltraining.utils.ErrorUtils;
import com.yaozheng.vocationaltraining.utils.http.okhttp.OkHttpClientManager;

import net.sf.json.JSONObject;

import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.EBean;

/**
 * 闯关之旅
 */
@EBean
public class MastersTourServiceImpl implements MastersTourService {
    IMastersTourView iMastersTourView;

    @Override
    public void init(IMastersTourView iMastersTourView) {
        this.iMastersTourView = iMastersTourView;
    }

    @Background
    @Override
    public void checkpointsProgress(int id) {
        try {
            OkHttpClientManager.getInstance().get(
                    Constants.ROOTURL + "/exam/master/info?id=" + id,
                    iMastersTourView.getToken(), new BaseView(iMastersTourView) {
                        @Override
                        public void responseSuccess(JSONObject jsonObject) {
                            iMastersTourView.checkpointsProgressSuccess(jsonObject);
                        }

                        @Override
                        public void responseError(String error) {
                            iMastersTourView.checkpointsProgressError(error);
                        }


                    });
        } catch (Exception e) {
            ErrorUtils.outErrorLog(e);
            if (iMastersTourView.isResponseResult()) {
                iMastersTourView
                        .checkpointsProgressError(ErrorUtils.SERVER_CONNECTION_ERROR);
            }

        }
    }
}
